package com.yenlien.traceyun.plant.dao;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.plant.entity.ColdCategory;
import com.yenlien.traceyun.webase.dao.BaseJpaDao;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Date 2022/9/28
 * @Author jiaLong
 * @Descript
 */
public interface ColdCategoryDao extends BaseJpaDao<ColdCategory> {


    @Query(value = "SELECT * FROM t_cold_category WHERE (parent_id IS NULL OR parent_id = '') AND `type` = ?1", nativeQuery = true)
    List<ColdCategory> loadAllParent(String type);


    @Query(value = "SELECT id FROM t_cold_category WHERE `label` = ?1", nativeQuery = true)
    String checkByLabel(String label);

    @Query(value = "SELECT `label`, parent_id FROM t_cold_category WHERE `label` = ?1", nativeQuery = true)
    JSONObject getByLabel(String label);

    List<ColdCategory> findByType(String type);

}
